import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author ChangLiang
 * @date 2020/12/20
 */
public class YoutubeDl {

    public static void main(String[] args) {

        String[] names = {
                ""
        };

        for (String name : names) {
            execute("C:\\Users\\bellychang\\Downloads\\youtube-download\\",name);
        }
    }

    public static void execute(String path, String name){

        Runtime rm = Runtime.getRuntime();
        try {
            String step = "cmd /c " + path + "youtube-dl --proxy socks5://127.0.0.1:1080/ https://www.youtube.com/watch?v=" + name;

            //执行命令
            Process process = rm.exec(step);

            System.out.println("开始执行");

            //关闭流释放资源
            if(process != null){
                process.getOutputStream().close();
            }


            InputStream in = process.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String tmp;
            while ((tmp = br.readLine()) != null) {
                System.out.println(tmp);
            }

        }catch(Exception e){
            e.printStackTrace();
            System.out.println("执行命令时出错");
        }
    }
}
